// Declaration de variables externes.
uniform extern float4x4 gWVP;
uniform extern float3 gEyePos;

static float3 gFogColor = {0.5f, 0.5f, 0.5f};
static float gFogStart = 1.0f;
static float gFogRange = 200.0f;

// Concordance de la structure de vertex CPU-GPU
struct OutputVS
{
	float4 posH : POSITION0;
	float4 color : COLOR0;

	// Vertex data
	float fogLerpParam : TEXCOORD0;
};

// Effectue les mathematiques
OutputVS TransformVS(float3 posL : POSITION0, float4 color: COLOR0)
{
	OutputVS outVS = (OutputVS)0;

	outVS.posH = mul(float4(posL, 1.0f), gWVP);
	outVS.color = color;

	float dist = distance(posL, gEyePos);
	outVS.fogLerpParam = saturate((dist - gFogStart) / gFogRange);

	return outVS;
}

// Echantillonne et Affiche les couleurs
float4 TransformPS(float4 color: COLOR0, float fogLerpParam : TEXCOORD0) : COLOR
{
	return float4(lerp(color, gFogColor, fogLerpParam), 1.0f);
}

technique TransformTech
{
	pass P0
	{
		vertexShader = compile vs_2_0 TransformVS();
		pixelShader = compile ps_2_0 TransformPS();

		//FillMode = WireFrame;
	}
}